package oj;

import java.util.Scanner;

/**
 * @author 郝文雪
 * @date 2022/7/16 11:19
 * @Description Test
 */
public class Day18字符串通配符 {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            String s1=sc.nextLine();
            String s2=sc.nextLine();
            System.out.println(match(s1,s2));

        }
    }
    private static boolean match(String t,String s){
        char[] ct=t.toCharArray();
        char[] cs=s.toCharArray();
        int lt=ct.length;
        int ls=cs.length;
        boolean[][] arr=new boolean[ls+1][lt+1];
        arr[0][0]=true;
        for(int i=0;i<=ls;i++){
            for(int j=1;j<=lt;j++){
                if(ct[j-1]=='*'){
                    if(i==0){
                        arr[i][j]=arr[i][j-1];
                    }else{
                        if(cs[i-1]=='.' || (cs[i-1]>='0'&& cs[i-1]<='9') ||
                                (cs[i-1]>='a'&& cs[i-1]<='z') || (cs[i-1]>='A'&& cs[i-1]<='Z')){
                            arr[i][j]=arr[i-1][j] || arr[i][j-1];
                        }
                    }
                }else{
                    if(i>0 && defs(ct[j-1],cs[i-1])){
                        arr[i][j]=arr[i-1][j-1];
                    }
                }
            }
        }
        return arr[ls][lt];
    }
    private static boolean defs(char t, char s){
        if(t=='?') return true;
        if(t>='a' && t<='z'){
            t=(char)(t-'a'+'A');
        }
        if(s>='a' &&s<='z'){
            s=(char)(s-'a'+'A');
        }
        return s==t;
    }
}
